Skip to content

Festplatte in Linux vergrößern

In diesem Fall wurde die Festplatte /dev/sda um 100G, auf 200G vergrößert.

Als erstes melden wir uns am Server an und lassen uns die aktuelle Partitionstabelle anzeigen.

root:~# fdisk -l /dev/sda
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Disk model: Virtual Disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 0D132E7B-29A6-4CB6-AB76-543C6AF3C1CD

Device         Start       End   Sectors  Size Type
/dev/sda1       2048   1050623   1048576  512M EFI System
/dev/sda2    1050624 386926591 385875968  184G Linux filesystem
/dev/sda3  386926592 418383871  31457280   15G Linux swap

Mit d (delete) löschen wir die Partition 3 und 2.

root:~# fdisk /dev/sda

Command (m for help): d
Partition number (1-3, default 3): 3

Partition 3 has been deleted.

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Mit n (new) erstellen wir die Partition 2 von Start 1050624 - End +183G

Command (m for help): n
Partition number (2-128, default 2): 2
First sector (1050624-419430366, default 1050624): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-419430366, default 419430366): +183G

Created a new partition 2 of type 'Linux filesystem' and of size 183 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Mit n (new) erstellen wir die Partition 3 von Start 384829440 - End +16G

Command (m for help): n
Partition number (3-128, default 3): 3
First sector (384829440-419430366, default 384829440): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (384829440-419430366, default 419430366): +16G

Created a new partition 3 of type 'Linux filesystem' and of size 16 GiB.

Mit p (print) lassen wir uns den aktuellen Status anzeigen.

Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Disk model: Virtual Disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 0D132E7B-29A6-4CB6-AB76-543C6AF3C1CD

Device         Start       End   Sectors  Size Type
/dev/sda1       2048   1050623   1048576  512M EFI System
/dev/sda2    1050624 384829439 383778816  183G Linux filesystem
/dev/sda3  384829440 418383871  33554432   16G Linux filesystem

Mit t (type) definieren wir den Partitions-Type. Nr. 19 steht für Linux Swap, Nr. 20 steht für Linux filesystem,

Command (m for help): t
Partition number (1-3, default 3): 3
Partition type (type L to list all types): 19

Changed type of partition 'Linux filesystem' to 'Linux swap'.

Mit p (print) lassen wir uns den aktuellen Status anzeigen.

Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Disk model: Virtual Disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 0D132E7B-29A6-4CB6-AB76-543C6AF3C1CD

Device         Start       End   Sectors  Size Type
/dev/sda1       2048   1050623   1048576  512M EFI System
/dev/sda2    1050624 384829439 383778816  183G Linux filesystem
/dev/sda3  384829440 418383871  33554432   16G Linux swap

Mit w (write) schreieb wir die Partitionstabelle.

Command (m for help): w
The partition table has been altered.
Syncing disks.

Nun starten wir das System neu.

root:~# reboot

Nach dem Neustart erweitern wir die Partition /dev/sda2.

root:~# resize2fs /dev/sda2
resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 11, new_desc_blocks = 23
The filesystem on /dev/sda2 is now 47972352 (4k) blocks long.

Mit mkswap erstellen wir die Swap Partition.

root:~# mkswap /dev/sda3
Setting up swapspace version 1, size = 16 GiB (17179865088 bytes)
no label, UUID=199145b5-1317-4c9f-b599-5fcd58a29182

Die neue UUID=199145b5-1317-4c9f-b599-5fcd58a29182 ersetzten wir mit der alten in der /etc/fstab.

root:~# vi /etc/fstab

Mit swapon aktivieren wir den Swap Space,

root:~# swapon -a